<?php
	include $setupdata['core_dir']."/modules/payment/gateway/prepayclass.php";
	$prepayclass = new prepayclass;
	
	if ($act=="save"){
		$prepay_data = array();
		if (isset($_POST["INVOICE_TMP"])) $prepay_data['INVOICE_TMP']=$_POST["INVOICE_TMP"]; else $prepay_data['INVOICE_TMP']="";

		foreach($prepay_data as $prepay_key=>$prepay_value) {
			if ($prepay_value == "") $err->AddError(25, "payment_prepay");
			else $prepay_data[$prepay_key] = trim($prepay_data[$prepay_key]);
		}

		if (isset($_POST["URL_OK"])) $prepay_data['URL_OK']=trim($_POST["URL_OK"]); else $prepay_data['URL_OK']="";
		if (isset($_POST["URL_CANCEL"])) $prepay_data['URL_CANCEL']=trim($_POST["URL_CANCEL"]); else $prepay_data['URL_CANCEL']="";
		
		$prepay = addslashes(serialize($prepay_data));
		$mysqlclass->mysql_my_query("DELETE FROM `".$setupdata['table_prefix']."local_vars` WHERE 'payment_gateway_prepay'=`name`", __LINE__, __FILE__);
		$mysqlclass->mysql_my_query("INSERT INTO `".$setupdata['table_prefix']."local_vars` (`id`,`name`,`value`) VALUES ('', 'payment_gateway_prepay', '".$prepay."')", __LINE__, __FILE__);
		
		unset($prepay_tmp);
		unset($prepay_data);
		unset($prepay_key);
		unset($prepay);
	} elseif ($act == "print_invoice") {
		$data = $paymentclass->get_gateway_data('prepay');
		$invoice_data = unserialize(stripcslashes(base64_decode($_POST['invoice_data'])));
		$tempalate = $setupdata['smarty_compile_dir']."prepay_invoice_tmp";
		$fp = fopen($tempalate, "w"); fwrite($fp, $data['INVOICE_TMP']); fclose($fp);
		$tmp = $smarty->template_dir;
		$smarty->template_dir = "";
		$smarty->assign("invoice_data", $invoice_data['data']);
		$smarty->assign("invoice_info", $invoice_data['post']);
		if ($smarty->template_exists($tempalate)) $output = $smarty->fetch($tempalate);
		$smarty->template_dir = $tmp;
		print_r($output);
		if (is_file($tempalate)) @unlink($tempalate);
		$mysqlclass->close_db();
		die();
	}
?>